package ru.truba.touchgrallery.GalleryWidget;
import java.util.List;

import ru.truba.touchgrallery.TouchView.UrlTouchImageView;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.Image;
import ohos.app.Context;

/**
 * Created by fabio on 28/05/14.
 */
public class InfinityUrlAdapter extends BasePagerAdapter {
private  Object object;
    private int TOTAL_PAGES = -1;
    private int MIN_LOOPS = 1000;
    // You can choose a bigger number for LOOPS, but you know, nobody will fling
    // more than 1000 times just in order to test your "infinite" ViewPager :D
    public int FIRST_PAGE = 1;
    //private ImageView.ScaleType mScaleType = null;

   Image.ScaleMode  mScaleType = null;
    public InfinityUrlAdapter(Context context, List<String> resources) {
        super(context, resources);
        TOTAL_PAGES = resources.size();
        FIRST_PAGE = TOTAL_PAGES * MIN_LOOPS / 2;
 /*       addDataSubscriber(new DataSetSubscriber() {
            @Override
            public void onItemInserted(int position) {
                super.onItemInserted(position);
                ((GalleryViewPager)componentContainer).mCurrentView = ((UrlTouchImageView)object).getImageView();            }
        });*/
    }


    @Override
    public Object createPageInContainer(ComponentContainer collection, int position) {
        position = position % TOTAL_PAGES;
        final UrlTouchImageView iv = new UrlTouchImageView(mContext);
        iv.setUrl(mResources.get(position));
        iv.setLayoutConfig(new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT));
        if(mScaleType != null) {
            iv.setScaleType(mScaleType);
        }
        collection.addComponent(iv, 0);
        object=iv;
        return iv;
    }

    /**
     * Set Scaletype for ImageView
     * @param scaletype
     */
    public void setScaleTypeForImageView(Image.ScaleMode scaletype) {
        mScaleType = scaletype;
    }

    @Override
    public int getCount() {
        return TOTAL_PAGES * MIN_LOOPS;
    }
};